<?php

class BackupScheduleAddForm extends CFormModel
{
	public $name;
	public $id_group;
	public $cpanel_accounts;
	public $id_backup_locations;
	public $email;
	public $delay;
	public $status;
	public $days;
	public $hour;
	
	public $group_account_host;

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('name, cpanel_accounts, email, delay, status, days, hour', 'required'),
			array('status', 'numerical', 'integerOnly'=>true),
			array('delay', 'numerical', 'integerOnly'=>true, 'min'=>30),
			array('name, id_group, cpanel_accounts, id_backup_locations, email, delay, status, days, hour, group_account_host', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('name, id_group, cpanel_accounts, id_backup_locations, email, delay, status, days, hour, group_account_host', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'name' => t('info', 'Name'),
			'cpanel_accounts' => t('info', 'Select cPanel Accounts To Backup'),
			'id_backup_locations' => t('info', 'Backup Location'),
			'email' => t('info', 'Confirmation Email Address'),
			'delay' => t('info', 'Time Between Backups'),
			'status' => t('info', 'Select Status'),
			'days' => t('info', 'Days To Backup'),
			'hour' => t('info', 'Select Hour'),
		);
	}
	
	public function getFieldLabel($field)
	{
		$labels = $this->attributeLabels();
		
		return empty($labels[$field])? '' : $labels[$field];
	}
	
	public function listGetBy()
	{
		return array(
			'id_group' => 'By Group',
			'id_account' => 'By Account',
			'id_host' => 'By Host'
		);
	}
	
	public function listAccounts()
	{
		return CHtml::listData(WhmAccount::model()->findAllByPk(User::model()->getFinalAccessdAccountIds()), 'id_account', 'domain');
	}

	public function listHosts()
	{
		return CHtml::listData(Host::model()->findAll(), 'id_host', 'name');
	}
		
	public function listGroups()
	{
		return CHtml::listData(Group::model()->findAllByPk(User::model()->getFinalAccessdGroupIds()), 'id_group', 'name');
	}
	
	public function listBackupLocation()
	{
		return CHtml::listData(BackupLocations::model()->findAll(), 'id_backup_locations', 'name');
	}
	
	public function listStatus()
	{
		return array(
			BackupSchedule::STATUS_ACTIVE => 'Active',
			BackupSchedule::STATUS_SUSPENDED => 'Suspended'
		);
	}
	public function listDays()
	{
		return array(
			BackupSchedule::Sun => 'Sunday',
			BackupSchedule::Mon => 'Monday',
			BackupSchedule::Tue => 'Tuesday',
			BackupSchedule::Wed => 'Wednesday',
			BackupSchedule::Thur => 'Thursday',
			BackupSchedule::Fri => 'Friday',
			BackupSchedule::Sat => 'Saturday'
		);
	}
	
	public function listHours()
	{
		return array(
			0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ,14 ,15, 16, 17, 18, 19, 20, 21, 22, 23
		);
	}
}